#include<iostream>
#include<string.h>
using namespace std;
typedef int hptype;
typedef struct Heap
{
	hptype* a;
	int size;
	int capacity;
}Heap;
void Print(int a[], int n)
{
	int i = 0;
	for (i; i < n; i++)
	{
		cout << a[i] << ' ';
	}
	cout << endl;
}
void InitHP(Heap* h,int a[],int n)
{
	h->a = new int[n];
	memcpy(h->a, a, n * sizeof(int));
	h->capacity = n;
	h->size = n;
}
void AdjustUp(Heap* hp,int child)
{
	int parent = (child - 1) / 2;
	while (child && hp->a[parent] < hp->a[child])
	{
		std::swap(hp->a[parent] , hp->a[child]);
		child = parent;
		parent = (child - 1) / 2;
	}
}


void AdjustDown(Heap* hp, int parent)
{
	int child = parent * 2 + 1;
	while (child < hp->size)
	{
		if (child + 1 < hp->size && hp->a[child] < hp->a[child + 1])
		{
			child++;
		}
		if (hp->a[child] > hp->a[parent])
		{
			std::swap(hp->a[parent], hp->a[child]);
			parent = child;
			child = parent * 2 + 1;
		}
		else
			break;
	}
}

void HeapSort(int* a, int n)
{
	Heap hp;
	InitHP(&hp, a, n);
	for (int i = (n  - 1) / 2; i >= 0; i--) {
		AdjustDown(&hp, i);
	}
	int end = n - 1;
	Print(hp.a, n);
	while (end > 0) {
		std::swap(hp.a[0], hp.a[end]);
		end--;
		hp.size--;
		AdjustDown(&hp, 0);
		Print(hp.a, n);
	}
}
int main()
{
	int a[200] = { 0 };
	int n = 0;
	while (1)
	{
		int x = 0;
		cin >> x;
		if (x == 0)
			break;
		else
			a[n++] = x;
	}
	//Print(a, n);
	HeapSort(a, n);
}
//12 9 26 11 38 52 99 27 66 15 32 0